package com.liyuan.help_e.controller;

import com.liyuan.help_e.model.News;
import com.liyuan.help_e.model.ResultJson;
import com.liyuan.help_e.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class NewsController {
    @Autowired
    NewsService newsService;
    @GetMapping("/news/{id}")
    public void news_Html(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/news.html").forward(request,response);
    }
    @PostMapping("/news/{id}")
    public ResultJson news(@PathVariable("id")Integer id){
        News news =newsService.selectNewsById(id);
        return new ResultJson(200,"get news success!",news);
    }
}
